import * as React from 'react'
import {compose} from 'recompose'
import {curry} from 'ramda'
import {QueryComponent} from '../util/index'

export default curry(({gql, options = {}}, ComposedComponent: React.Component) => {
    class WithQuery extends React.Component {
        render() {
            const thisOptions = typeof options == 'function' ? options(this.props) : options
            return (
                <div>
                    <QueryComponent gql={gql} options={thisOptions}
                                    render={props => (
                                        props ? <ComposedComponent {...this.props} {...props}/> : <div/>
                                    )}
                    />
                </div>
            )
        }
    }

    return WithQuery
})